package base;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.example.zx.theline.R;

import Utils.ActivityManager;
import app.MyApplication;
import dialog.CenterDialog;

import static app.MyApplication.reInitApp;

/**
 * Created by 任科全 on 2017/3/13.
 */

public abstract class BaseActivity extends AppCompatActivity {

    private CenterDialog mCenterDialog;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {


        //去除所有activity标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        //沉浸式状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //防止小键盘影响布局
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

        super.onCreate(savedInstanceState, persistentState);

//        if(MyApplication.APP_STATUS!=MyApplication.APP_STATUS_NORMAL){
//            reInitApp();
//            finish();
//        }
    }


    @Override
    protected void onResume() {
        //保持竖屏显示
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        super.onResume();

    }


    protected abstract void InitView();

    protected abstract void InitData();

    protected abstract void InitListen();

    /**
     * 2017.7.20 新增 将activity增加至activitymanager
     */

    @Override
    protected void onStart() {
        super.onStart();
        ActivityManager.getInstance().addActivity(this);
    }

    @Override
    public void finish() {
        super.finish();
    }

    public void showCenterDialog(Context context, String message, CenterDialog.CenterClick centerClick) {
        if (mCenterDialog == null) {
            mCenterDialog = new CenterDialog(context,centerClick);
        }
        mCenterDialog.setMessage(message);
        mCenterDialog.show();
    }

    public void hideCenterDialog() {
        if (mCenterDialog != null)
            mCenterDialog.hide();
    }

}
